const express = require('express');
const router = express.Router();

/**
 * @param {Object} options
 * @param {} options.code 编号
 * @param {} options.partContractInvoiceCode 备件箱单发票编号
 * @param {} options.status 状态  1-待发运  2-已发运  3-已签收  -1-作废
 * @param {} options.partShipOrderStatus 委托书状态  1-未生成  2-已生成
 * @param {} options.partShipNoticeStatus 通知书状态  1-未生成  2-已生成
 * @param {} options.beginInvoicedDate 开票日期-开始时间
 * @param {} options.endbeginInvoicedDate 开票日期-结束时间
 * @param {} options.pageSize 每页数据量
 * @param {} options.pageIndex 指定页
 * @param {} options.sortField 排序字段
 * @param {} options.isDesc 倒序排列
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forPartShipOrder', async(req, res, next) => {
    const options = {
        code: req.query.code,
        partContractInvoiceCode: req.query.partContractInvoiceCode,
        status: req.query.status,
        partShipOrderStatus: req.query.partShipOrderStatus,
        partShipNoticeStatus: req.query.partShipNoticeStatus,
        beginInvoicedDate: req.query.beginInvoicedDate,
        endbeginInvoicedDate: req.query.endbeginInvoicedDate,
        pageSize: req.query.pageSize,
        pageIndex: req.query.pageIndex,
        sortField: req.query.sortField,
        isDesc: req.query.isDesc
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id45',
                    brandId: 'brandId46',
                    code: 'code47',
                    partContractInvoiceCode: 'partContractInvoiceCode48',
                    invoicedDate: '2019-09-05T05:56:17Z',
                    status: 1,
                    partShipOrderStatus: 1,
                    partShipNoticeStatus: 1,
                    shipmentType: 1,
                    origin: 'origin',
                    destination: 'destination',
                    forwarder: 'forwarder',
                    invoiceAmount: 1,
                    seller: 'seller',
                    buyer: 'buyer',
                    priceTerms: 1,
                    shippingMark: 'shippingMark',
                    companySeal: 'companySeal',
                    volumeTotal: 1,
                    packingListTotal: 1,
                    grossWeightTotal: 1
                },
                {
                    id: 'id49',
                    brandId: 'brandId50',
                    code: 'code51',
                    partContractInvoiceCode: 'partContractInvoiceCode52',
                    invoicedDate: '2019-09-05T05:56:17Z',
                    status: 1,
                    partShipOrderStatus: 1,
                    partShipNoticeStatus: 1,
                    shipmentType: 1,
                    origin: 'origin',
                    destination: 'destination',
                    forwarder: 'forwarder',
                    invoiceAmount: 1,
                    seller: 'seller',
                    buyer: 'buyer',
                    priceTerms: 1,
                    shippingMark: 'shippingMark',
                    companySeal: 'companySeal',
                    volumeTotal: 1,
                    packingListTotal: 1,
                    grossWeightTotal: 1
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
router.get('/forpartShipNotice', (req, res) => {
    const content = [];
    for(let i = 1; i <= 20; i++) content.push({
        partShipmentId: `${i}`,
        code: `CODE${i}`,
        partInvoiceCode: 'string',
        invoicedDate: '2019-09-06T08:19:56.549Z',
        partShipOrderStatus: 1,
        partShipNoticeStatus: 1,
        partShipmentStatus: 1,
        shipmentType: 1,
        origin: 'string',
        destination: 'string',
        carrierId: '1',
        carrierName: '货代1',
        invoiceAmount: 100
    });
    res.json(
        {
            message: '',
            payload: {
                content,
                totalElements: 100,
            }
        }
    );
});
router.get('/:id/forpartShipNotice', (req, res) => {
    const content = [];
    const id = 'id1';
    res.json(
        {
            message: '',
            payload: {
                partShipmentId: `${id}`,
                code: `CODE${id}`,
                partInvoiceCode: 'string',
                invoicedDate: '2019-09-06T08:19:56.549Z',
                partShipOrderStatus: 1,
                partShipNoticeStatus: 1,
                partShipmentStatus: 1,
                shipmentType: 1,
                origin: 'string',
                destination: 'string',
                carrierId: '1',
                carrierName: '货代1',
                invoiceAmount: 100
            }
        }
    );
});
router.get('/', (req, res) => {
    const content = [];
    for(let i = 1; i <= 20; i++) content.push({
        id: `${i}`,
        code: `CODE${i}`,
        dealerCode: 'string',
        partContractInvoiceCode: `FP201902125145${i}`,
        invoicedDate: '2019-04-17T05:13:36.246Z',
        shipmentType: 1,
        expectShipmentDay: 100,
        actualShipmentDay: 90,
        origin: 'origin-string',
        destination: 'destination-string',
        shipmentDate: '2019-04-17T05:13:36.246Z',
        expectDepartedDate: '2019-04-17T05:13:36.246Z',
        actualDepartedDate: '2019-04-17T05:13:36.246Z',
        expectArrivalDate: '2019-04-17T05:13:36.246Z',
        actualArrivalDate: '2019-04-17T05:13:36.246Z',
        declarePlace: 1,
        declareType: 1,
        receipterName: `receipterName${i}`,
        status: 1,
        shipmentNumber: 'shipmentNumber-string',
        rowVersion: 'string',
        options: [
            'shipment'
        ]
    });
    res.json(
        {
            message: '',
            payload: {
                content,
                totalElements: 100,
            }
        }
    );
});

router.get('/:id', (req, res) => {
    res.json({
        payload: {
            id: '1',
            code: 'code',
            dealerCode: 'string',
            partContractInvoiceCode: 'FP2019021251451',
            invoicedDate: '2019-04-17T05:13:36.246Z',
            shipmentType: 1,
            expectShipmentDay: 100,
            actualShipmentDay: 90,
            origin: 'origin-string',
            destination: 'destination-string',
            shipmentDate: '2019-04-17T05:13:36.246Z',
            expectDepartedDate: '2019-04-17T05:13:36.246Z',
            actualDepartedDate: '2019-04-17T05:13:36.246Z',
            expectArrivalDate: '2019-04-17T05:13:36.246Z',
            actualArrivalDate: '2019-04-17T05:13:36.246Z',
            declarePlace: 1,
            declareType: 1,
            receipterName: 'receipterName',
            status: 1,
            shipmentNumber: 'shipmentNumber-string',
            rowVersion: 'string',
            options: [
                'shipment'
            ],
            declareAttachments: [
                {
                    fileId: 'declareId',
                    fileName: '下载报关附件清单1'
                }
            ],
            clearanceAttachments: [
                {
                    fileId: 'clearanceId',
                    fileName: '下载清关附件清单1'
                }
            ]
        }
    });
});
router.post('/import', (req, res) => {
    res.json({
        message: 'success'
    });
});
router.put('/:id/shipment', (req, res) => {
    res.json({
        message: 'success'
    });
});

module.exports = router;
